package net.joint_painting.shared.logic;

/**
 * @author CAM
 * @version $Revision: 1.0 $
 */
public class Surface {

    public final static Integer size = 200;

    /**
     * Method getSurfaceID.
     * 
     * @param id
     *            String
     * @param areaX
     *            Integer
     * @param areaY
     *            Integer
     * 
     * @return String
     */
    public static String getSurfaceID(String id, Integer areaX, Integer areaY) {
	return id + "_" + (areaX / size) + "x" + (areaY / size);
    }

    /**
     * Method getSurfacePositionX.
     * 
     * @param x
     *            Integer
     * 
     * @return Integer
     */
    public static Integer getSurfacePositionX(Integer x) {
	return x - x % size;
    }

    /**
     * Method getSurfacePositionY.
     * 
     * @param y
     *            Integer
     * 
     * @return Integer
     */
    public static Integer getSurfacePositionY(Integer y) {
	return y - y % size;
    }

    /**
     * Method getXFromID.
     * 
     * @param id
     *            String
     * 
     * @return Integer
     */
    public static Integer getXFromID(String id) {
	try {
	    String[] str = id.split("_");
	    String[] xStr = str[str.length - 1].split("x");
	    Integer x = Integer.valueOf(xStr[0]);
	    return x * size;
	} catch (Exception e) {
	    e.printStackTrace();
	    return 0;
	}
    }

    /**
     * Method getYFromID.
     * 
     * @param id
     *            String
     * 
     * @return Integer
     */
    public static Integer getYFromID(String id) {
	try {
	    String[] str = id.split("_");
	    String[] yStr = str[str.length - 1].split("x");
	    Integer y = Integer.valueOf(yStr[1]);
	    return y * size;
	} catch (Exception e) {
	    e.printStackTrace();
	    return 0;
	}
    }

}
